package top.wettis.chat.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.wettis.chat.mapper.TaskMapper;
import top.wettis.chat.pojo.DO.Task;
import top.wettis.chat.service.ITaskService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 任务表 服务实现类
 * </p>
 *
 * @author wettis
 * @since 2023-03-25
 */
@Service
@Slf4j
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
    @Autowired
    private TaskMapper taskMapper;


    @Override
    public void Insert(int i, String string, Integer toString) {
        taskMapper.initTask(i, string, toString);

    }

    @Override
    public List<Task> select(int id) {
        return taskMapper.selectByIdddd(id);
    }

    @Override
    public void deleteAll(int userid) {
        taskMapper.deleteAll(userid);
    }

    @Override
    public int selectTotal(Integer id) {
        return taskMapper.tatal(id);
    }

    @Override
    public void updateJD(int i, int jds, int userId) {
        taskMapper.updatejds(i, jds, userId);
    }

    @Override
    public HashMap<String, Object> getStatePlan(int userid) {

        HashMap<String, Object> result = new HashMap<>();
        result.put("id" , userid);
        int tatal = taskMapper.tatal(userid);
        HashMap<Integer, String> state = new HashMap<>();

        for (int i = 1; i <= tatal; i++) {
            int c = taskMapper.selectCur(userid, i);
            int t = taskMapper.selectTot(userid, i);

            double st = c * 100.0 / t;
//            log.info(String.valueOf(st));
            if ((int)st == 100){
                state.put(i , "success");
            } else {
                state.put(i , String.valueOf(st));
            }
            System.out.println(st);

        }
        result.put("进度" , state);
        return result;
    }


}
